<template>
	<view>
		<view class="movie-top">
			<uni-icons type="left" size="30" @click="goBack()" style="margin-right: 20rpx;"></uni-icons>
			<view class="top-region" @click="select_city()">
				<text>{{ map.city || '请选择城市'}}</text>
				<image src="https://picture-1326598115.cos.ap-nanjing.myqcloud.com/2025/09/24db001ebcaa394dc6a823f9393c74646bmovie-xiala.png"></image>
			</view>
			<view class="top-tab-list">
				<view class="tab-list-items" @click="gettab(value.type,index)"
					:class="{'sel-item':value.type==tanIndex}" v-for="(value,index) in tabLists" :key="index">
					{{ value.text }}
					<view class="cut-img" v-if="tanIndex==value.type"></view>
				</view>
			</view>
			<!-- <image src="../../static/images/movie-serchs.png" class="sechut"></image> -->
		</view>
		<scroll-view :scroll-y="true" class="scroll-Y">
			<view class="movie-main">

				<view class="movie-list" v-for="(value,index) in dataList" :key="value.id" @click="getUrl(value)">
					<view class="movie-img">
						<image :src="value.image"></image>
					</view>
					<view class="movie-info">
						<view class="mo-info-top">
							<view class="tiel">{{value.filmName}}</view>
							<view class="movie-d">{{value.versionType}}</view>
						</view>
						<view class="director">评分：{{value.score}}</view>
						<view class="director">导演：{{value.director}}</view>
						<view class="to-star">主演：{{value.cast}}</view>

						<view class="calss-item">
							<view class="classify-item">{{value.duration}}分钟</view>
						</view>
					</view>
					<view class="movie-btns" v-if="tanIndex==1">购票</view>
				</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	import sheep from '@/sheep';
	export default {
		data() {
			return {
				tabLists: [{
						text: '正在热映',
						type: 1,
						isLoad: false,
						list: []
					},
					// {
					// 	text: '即将上映',
					// 	type:2,
					// 	isLoad:false,
					// 	list:[]
					// }
				],
				tanIndex: 1,
				rateValue: 3,
				dataList: [],
				index: 0,
				show: false,
				cityList: [],
				keyWord: '',
				cityShowList: [],
				isLoad: false,
				map: {
					city: '',
					id: 0
				},
				wellList: [], //所有热映数据
				soonList: [], //所有即将上映数据
				page: 1
			}
		},
		onLoad() {

			// this.getList()
			// this.getFilmList()
		},
		onReachBottom() {
			// this.page++
			// if(this.tanIndex==1){
			// 	this.dataList = this.dataList.concat(config.pageDataFn(this.page,8,this.wellList))
			// }else{
			// 	this.dataList = this.dataList.concat(config.pageDataFn(this.page,8,this.soonList))
			// }
		},
		async onShow() {
			if (uni.getStorageSync('map') && uni.getStorageSync('map').id != this.map.id) {
				this.map = uni.getStorageSync('map');
				console.log(999, this.map)
				this.loading = true;
				this.getFilmList(this.map.id)
				// await this.movieHotList();
				// await this.movieSoonList();
				this.loading = false;
			} else {
				this.getCityList()
			}
		},
		methods: {
			goBack() {
				uni.navigateBack({delta: 1})
			},
			async getCityList() {
				const res = await sheep.$api.movie.getCityList();
				console.log('res',res.data[0])
				if(!uni.getStorageSync('map')) {
					uni.setStorageSync('map', {id: res.data[0].id, city: res.data[0].cityName});
					this.map = uni.getStorageSync('map');
					console.log('this.map',this.map)
					this.getFilmList(this.map.id)
				}
			},
			async getFilmList(id) {
				const res = await sheep.$api.movie.filmList({
					cityId: id
				});
				if (res.state === 200) {
					this.dataList = res.data
					this.dataList.push()
				}
				console.log('res', res)
			},
			// 选择城市
			select_city() {
				uni.navigateTo({
					url: '/pages/movie/address_city'
				});
			},
			//跳转到电影院列表
			getUrl(data) {
				if (!this.map.id) {
					this.$toast("请选择位置信息")
					return false
				}
				let info = {
					position: this.map,
					info: data
				}
				console.log('电影',data)
				// return
				console.log(info)
				uni.navigateTo({
					url: '/pages/movie/cinema-list?params='+encodeURIComponent(JSON.stringify(info)),
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						// res.eventChannel.emit('filmDataFromOpene', {
						// 	data: info
						// })
					}
				})
			},
			gettab(type, index) {
				this.index = index
				if (this.tanIndex != type) {
					this.tanIndex = type
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F4F5F7;
	}
	.movie-top {
		display: flex;
		align-items: center;
		background-color: #FFFFFF;
		padding: 30rpx 32rpx;
		z-index: 9999;
		margin-top: 88rpx;
	}

	.top-region {
		display: flex;
		align-items: center;

		text {
			color: #636775;
			font-size: 28rpx;
		}

		image {
			width: 24rpx;
			height: 24rpx;
			margin-left: 8rpx;
		}
	}

	.top-tab-list {
		margin-left: 110rpx;
		display: flex;
		align-items: center;

		.tab-list-items {
			color: #636775;
			font-size: 28rpx;
			padding: 0rpx 25rpx;
			position: relative;
		}

		.sel-item {
			color: #2D3039 !important;
			font-size: 32rpx !important;
			font-weight: 600;
		}

		.cut-img {
			width: 52rpx;
			height: 8rpx;
			position: absolute;
			bottom: -30rpx;
			right: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			background-color: #FE602B;
		}
	}

	.sechut {
		margin-left: auto;
		width: 44rpx;
		height: 44rpx;
	}
	.scroll-Y {
		height: calc(100vh - 350rpx);
		margin-top: 20rpx;
		overflow: hidden;
	}

	.movie-list {
		margin: 0 25rpx 25rpx 25rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 28rpx 32rpx;
		display: flex;
		align-items: center;

		.movie-img {
			width: 180rpx;
			height: 248rpx;

			image {
				width: 180rpx;
				height: 248rpx;
				border-radius: 20rpx;
			}

		}

		.movie-info {
			margin-left: 24rpx;
			width: 50%;

			.mo-info-top {
				display: flex;
				align-items: center;

				.tiel {
					width: 216rpx;
					color: #2D3039;
					font-size: 32rpx;
					font-weight: 600;
				}

				.movie-d {
					margin-left: 20rpx;
					border-radius: 6rpx;
					border: 1rpx solid #C4C4C4;
					color: #A6A8AE;
					font-size: 17rpx;

					.zimu {
						padding: 2rpx 6rpx;
					}

					.shuzi {
						background-color: #C4C4C4;
						padding: 0rpx 6rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}


	.rate-item {
		display: flex;
		align-items: center;
		margin-top: 16rpx;

		.rate-nun {
			color: #FF6E06;
			font-size: 28rpx;
			font-weight: 550;
			margin-left: 16rpx;
		}

	}

	.director {
		color: #636775;
		font-size: 24rpx;
		margin-top: 16rpx;
	}

	.to-star {
		color: #787A82;
		font-size: 24rpx;
		margin-top: 10rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.calss-item {
		display: flex;
		align-items: center;
		margin-top: 12rpx;

		.classify-item {
			padding: 6rpx 12rpx;
			border-radius: 6rpx;
			border: 2rpx solid #DADCE4;
			color: #A6A8AE;
			font-size: 20rpx;
		}
	}

	.movie-btns {
		margin-left: auto;
		width: 110rpx;
		height: 58rpx;
		background: linear-gradient(207deg, #FF9272 0%, #FC5421 100%);
		border-radius: 29rpx;
		text-align: center;
		line-height: 58rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		font-weight: 550;
	}

	.region-top {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 20rpx;

		.region-left {
			width: 75%;
			border-radius: 40rpx;
			height: 68rpx;
			background-color: #F5F6F8;
			display: flex;
			align-items: center;
			padding-left: 30rpx;
		}

		.region-val {
			width: 90%;
			font-size: 30rpx;
		}

		.region-btn {
			background: linear-gradient(207deg, #FF9272 0%, #FC5421 100%);
			border-radius: 50rpx;
			height: 68rpx;
			text-align: center;
			width: 140rpx;
			line-height: 68rpx;
			color: #FFFFFF;
			font-size: 24rpx;
			font-weight: 550;
		}
	}

	.region-list {
		padding: 22rpx 35rpx;
		color: #2D3039;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2rpx solid #E2E2E2;
	}

	.empty {
		text-align: center;
		padding-top: 30rpx;
		color: #787A82;
		font-size: 24rpx;
	}

  .scroll-Y {
    height: calc(100vh - 250rpx); /* 原350rpx，减少100rpx填充底部空白 */
    margin-top: 20rpx;
    overflow: hidden;
  }
</style>
